class code1 {
    public List<List<Integer>> ret;
    public List<Integer> path;
    boolean[] check;
    public List<List<Integer>> permute(int[] nums) {
        ret = new ArrayList<>();
        check = new boolean[nums.length];
        dfs(nums);
        return ret;
    }
    public void dfs(int[] nums) {
        //递归
        if(nums.length==path.size()) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i=0;i<nums.length;i++) {
            if(check[i]==false) {
                path.add(nums[i]);
                check[i]=true;
                dfs(nums);
                //回溯
                check[i] = false;
                path.remove(path.size()-1);
            }
        }
    }
}
